package com.attendance.www.hr.service.impl;

import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.attendance.www.hr.beans.SystemConfigBean;
import com.attendance.www.hr.dao.mapper.SystemConfigureMapper;
import com.attendance.www.hr.entitys.SystemConfigure;
import com.attendance.www.hr.entitys.SystemConfigureExample;
import com.attendance.www.hr.service.ISystemConfigureService;

@Service
public class SystemConfigureServiceImpl implements ISystemConfigureService {
	@Resource
	private SystemConfigureMapper systemConfigureDao;

	@Override
	public Date getEffectiveDate() {
		// TODO Auto-generated method stub
		Date effectiveDate = systemConfigureDao.selectByExample(new SystemConfigureExample()).get(0).getEffectiveDate();
		if(effectiveDate==null) {
			effectiveDate= new Date();
		}
		return effectiveDate;
	}

	/**
	 * 获取配置表里，接收邮件的邮箱地址
	 */
	@Override
	public SystemConfigBean getEmail() {
		SystemConfigure systemConfigure=systemConfigureDao.selectByPrimaryKey(1);
		SystemConfigBean systemConfigBean=new SystemConfigBean();
		systemConfigBean.setMailName(systemConfigure.getMailName());
		systemConfigBean.setMailPassword(systemConfigure.getMailPassword());
		systemConfigBean.setTokenCount(systemConfigure.getTokenCount());
		return systemConfigBean;
	}

	/**
	 * 更新接收者邮箱
	 */
	@Override
	public boolean updateEmail(String emailAddress,String emailPassword) {
		// TODO Auto-generated method stub
		SystemConfigure sys = systemConfigureDao.selectByExample(new SystemConfigureExample()).get(0);
		sys.setMailName(emailAddress);
		sys.setMailPassword(emailPassword);
		int record = systemConfigureDao.updateByPrimaryKeySelective(sys);
		if (record >0) {
			return true;
		}
		return false;
	}



}
